﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Waker.Entitys;
using Waker.Common;

namespace Waker.BAL
{
    public class BAL_Cards : BAL_Base
    {
        #region 工地
        public DataTable GetAllConstructionSite()
        { return new DAL.DAL_Cards().GetAllConstructionSite(); }
        public DataTable GetConstructionSite(int id)
        {
            return new DAL.DAL_Cards().GetConstructionSite(id);
        }
        public bool SaveConstructionSite(DataRow dr)
        {
            return new DAL.DAL_Cards().SaveConstructionSite(dr);
        }
        public bool DeleteConstructionSite(int id)
        {
            return new DAL.DAL_Cards().DeleteConstructionSite(id);
        }
        #endregion
        #region 分包商
        public DataTable GetAllDepartment()
        {
            return new DAL.DAL_Cards().GetAllDepartment();
        }
        public DataTable GetDepartmentById(string id)
        { return new DAL.DAL_Cards().GetDepartmentById(id); }
        public bool SaveDepartment(DataRow dr)
        {
            return new DAL.DAL_Cards().SaveDepartment(dr);
        }
        public En_Result DeleteDepartment(string id)
        {
            return new DAL.DAL_Cards().DeleteDepartment(id);
        }
        #endregion
        #region 人员
        public DataTable EmployeeSeach(string name, string no, string idCard, bool? IsGrantCard, bool isLeave)
        {
            return new DAL.DAL_Cards().EmployeeSeach(name, no, idCard, IsGrantCard, isLeave);
        }
        public DataTable GetEmployeeByID(string id)
        {
            return new DAL.DAL_Cards().GetEmployeeByID(id);
        }
        public bool CheckEMployeeNo(string no)
        {
            return new DAL.DAL_Cards().CheckEMployeeNo(no);
        }
        public bool CheckEMployeeIDCardNo(string no)
        {
            return new DAL.DAL_Cards().CheckEMployeeIDCardNo(no);
        }
        public bool SaveEmployee(DataRow dr)
        {
            return new DAL.DAL_Cards().SaveEmployee(dr);
        }
        public int GetNextFingerId()
        {
            return new DAL.DAL_Cards().GetNextFingerId();
        }
        public bool UpdateEmployeeFingerId(string empId, int fingerId)
        {
            return new DAL.DAL_Cards().UpdateEmployeeFingerId(empId, fingerId);
        }
        public bool UpdateEmployeeFingerIndex(string empId, int index)
        {
            return new DAL.DAL_Cards().UpdateEmployeeFingerIndex(empId, index);
        }
        public DataTable GetEmpCardByEmp_ID(string empId)
        {
            return new DAL.DAL_Cards().GetEmpCardByEmp_ID(empId);
        }
        public bool SaveEmployeeCard(DataRow dr)
        {
            return new DAL.DAL_Cards().SaveEmployeeCard(dr);
        }
        public bool CheckEmployeeCardNo(string no)
        {
            return new DAL.DAL_Cards().CheckEmployeeCardNo(no);
        }
        public bool SetEmployeeLeave(string empID, bool isLeave)
        {
            return new DAL.DAL_Cards().SetEmployeeLeave(empID, isLeave);
        }
        public bool DeleteEmployee(string empID)
        {
            return new DAL.DAL_Cards().DeleteEmployee(empID);
        }
        public int ImportEmployee(DataTable dt)
        {
            return new DAL.DAL_Cards().ImportEmployee(dt);
        }
        #endregion
        #region 工资确认
        public En_Result SaveWages(string empId, int year, int month, DateTime fingerTime)
        {
            return new DAL.DAL_Cards().SaveWages(empId, year, month, fingerTime);
        }
        public DataTable EmployeeNoWagesSeach(int year, int month, string depID, string name, string no, string idCard)
        {
            return new DAL.DAL_Cards().EmployeeNoWagesSeach(year, month, depID, name, no, idCard);
        }
        #endregion

        #region 同步数据

        public DataSet GetNoUploadSubContractor()
        {
            return new DAL.DAL_Cards().GetNoUploadSubContractor();
        }
        public bool SetSubContractorDeletedUpload(string SerialNumber, bool isUpload)
        {
            return new DAL.DAL_Cards().SetSubContractorDeletedUpload(SerialNumber, isUpload);
        }
        public bool SetSubContractorUpload(string Dept_ID, int Dept_No, bool isUpload)
        {
            return new DAL.DAL_Cards().SetSubContractorUpload(Dept_ID, Dept_No, isUpload);
        }
        public DataSet GetNoUploadFingerEmployee()
        {
            return new DAL.DAL_Cards().GetNoUploadFingerEmployee();
        }
        public bool SetEmployeeDeletedUploadFinger(string SerialNumber, bool IsUploadFinger)
        {
            return new DAL.DAL_Cards().SetEmployeeDeletedUploadFinger(SerialNumber, IsUploadFinger);
        }
        public bool SetEmployeeUploadFinger(string empID, int fingerId, bool IsUploadFinger)
        {
            return new DAL.DAL_Cards().SetEmployeeUploadFinger(empID, fingerId, IsUploadFinger);
        }
        public DataSet GetNoUploadDeviceEmployee()
        {
            return new DAL.DAL_Cards().GetNoUploadDeviceEmployee();
        }
        public DataSet GetNoLoadDoorPerssion()
        {
            return new DAL.DAL_Cards().GetNoLoadDoorPerssion();
        }
        public bool SetEmployeeCardUploadDevice(string Emp_Card_ID, bool IsUpLoad)
        {
            return new DAL.DAL_Cards().SetEmployeeCardUploadDevice(Emp_Card_ID, IsUpLoad);
        }
        #endregion
        #region 初始化
        public List<En_CardAndEmployee> GetAllEmployeeAndCard()
        {
            List<En_CardAndEmployee> list = new List<En_CardAndEmployee>();
            var dt = new DAL.DAL_Cards().GetAllEmployeeAndCard();
            if (dt != null && dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    var en = new En_CardAndEmployee();
                    en.Card_No = dr["Card_No"] == DBNull.Value ? string.Empty : dr["Card_No"].ToString();
                    if (!string.IsNullOrEmpty(en.Card_No))
                    {
                        en.Card_WignNo = Util.GetCardNoByWigan(Convert.ToUInt32(en.Card_No));
                    }
                    en.Emp_ID = dr["Emp_ID"].ToString();
                    en.Emp_Name = dr["Emp_Name"].ToString();
                    en.Emp_No = dr["Emp_No"].ToString();
                    en.Dept_Name = dr["Dept_Name"].ToString();
                    en.Dept_ID = dr["Dept_ID"].ToString();
                    en.SiteName = dr["Site_Name"].ToString();
                    en.WorkTypeName = dr["WorkTypeName"] == DBNull.Value ? string.Empty : dr["WorkTypeName"].ToString();
                    en.Job = dr["Job"] == DBNull.Value ? string.Empty : dr["Job"].ToString();
                    en.Emp_Photo = dr["Emp_Photo"] == DBNull.Value ? null : (byte[])dr["Emp_Photo"];
                    list.Add(en);
                }
            }
            return list;
        }
        #endregion

        #region 人员权限
        public DataTable GetDoorPerssion(string deviceID, string depID, string name, string no, string idCard)
        {
            return new DAL.DAL_Cards().GetDoorPerssion(deviceID, depID, name, no, idCard);
        }
        public DataTable GetDoorPerssionByLSubDevice_ID(string LsubId)
        {
            return new DAL.DAL_Cards().GetDoorPerssionByLSubDevice_ID(LsubId);
        }
        public bool SaveDoorPermission(List<string> listEmpId, string subId)
        {
            return new DAL.DAL_Cards().SaveDoorPermission(listEmpId, subId);
        }
        #endregion
    }
}
